@echo off
setlocal enabledelayedexpansion

set "ROOT=%~dp0"
set "MODULE=%~1"

set "JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8"

if "%MODULE%"=="" (
  echo Usage: publish.bat ^<module^>
  echo Example: publish.bat log
  exit /b 1
)

set "CFG_PROP=%ROOT%versions\secret.properties"

if exist "%CFG_PROP%" (
  for /f "usebackq tokens=1,* delims==" %%A in ("%CFG_PROP%") do (
    if /I not "%%A"=="#" (
      if /I "%%A"=="mavenCentralUsername" set "ORG_GRADLE_PROJECT_mavenCentralUsername=%%~B"
      if /I "%%A"=="mavenCentralPassword" set "ORG_GRADLE_PROJECT_mavenCentralPassword=%%~B"
    )
  )
)

pushd "%ROOT%"
call .\gradlew :project:%MODULE%:publish --stacktrace
set "EXITCODE=%ERRORLEVEL%"
popd

exit /b %EXITCODE%
